use std::collections::BTreeMap;

use anyhow::Ok;
use hmac::{Hmac, Mac};
use jwt::{SignWithKey, VerifyWithKey};
use sha2::Sha256;

pub fn process_sign_jwt(sub: &str, aud: &str, exp: &str, secret: &[u8]) -> anyhow::Result<()> {
    let key: Hmac<Sha256> = Hmac::new_from_slice(secret).unwrap();
    let mut claims = BTreeMap::new();
    claims.insert("sub", sub);
    claims.insert("aud", aud);
    claims.insert("exp", exp);
    let token_str = claims.sign_with_key(&key).unwrap();
    println!("{}", token_str);
    Ok(())
}
pub fn process_verify_jwt(token: &str, secret: &[u8]) -> anyhow::Result<()> {
    let key: Hmac<Sha256> = Hmac::new_from_slice(secret).unwrap();
    let claims: BTreeMap<String, String> = token.verify_with_key(&key).unwrap();
    println!("{:?}", claims);
    Ok(())
}
